const md5 = require("md5");
const moment = require("moment");
const jwt = require("jwt-simple");
const KEY = "$%^&*i(o)p^&*()&*i(op&*";
module.exports = {
	getMd5(password){
		return md5(password+KEY);
	},
	getNowTime(){
		return moment().format("YYYY-MM-DD HH:mm:ss")
	},
	// 加密,默认一个小时后过期
	jwtEncode(payload,exp=60*60){
		return jwt.encode({
			...payload,
			exp:Date.now()/1000+exp
		},KEY)
	},
	jwtDecode(token){
		return new Promise((resolve)=>{
			const result = jwt.decode(token,KEY)
			resolve(result);
		})

	}

}